package cn.iocoder.yudao.module.erp.dal.mysql.stock.goods;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.module.erp.controller.admin.stock.goods.vo.GoodsPageReqVO;
import cn.iocoder.yudao.module.erp.dal.dataobject.stock.goods.GoodsDO;
import org.apache.ibatis.annotations.Mapper;

/**
 * 物品 Mapper
 *
 * @author maxuxu
 */
@Mapper
public interface GoodsMapper extends BaseMapperX<GoodsDO> {

    default PageResult<GoodsDO> selectPage(GoodsPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<GoodsDO>()
                .likeIfPresent(GoodsDO::getName, reqVO.getName())
                .eqIfPresent(GoodsDO::getCode, reqVO.getCode())
                .eqIfPresent(GoodsDO::getModels, reqVO.getModels())
                .eqIfPresent(GoodsDO::getBrand, reqVO.getBrand())
                .likeIfPresent(GoodsDO::getNameEn, reqVO.getNameEn())
                .betweenIfPresent(GoodsDO::getCreateTime, reqVO.getCreateTime())
                .eqIfPresent(GoodsDO::getDeleted, reqVO.getDeleted())
                .likeIfPresent(GoodsDO::getCategoryName,reqVO.getCategoryName())
                .orderByDesc(GoodsDO::getId));
    }

    default GoodsDO selectByCode(String code){
        return selectOne(GoodsDO::getCode, code);
    }
}